const app = getApp()

export default {
	name: 'room-swither',
	data(){
		return {
			get:{
				rooms:[],				// 房号
			},
			room:0,					// 当前选中的卡索引
		}
	},
	computed:{
		bindeds(){
			let i = 0
			return this.get.rooms.map(room=>{
				if(room.isDefault){
					this.room = i
				}
				i++
				return {
					label: `${room.courtName}${room.buildingName}${room.unit}单元${room.no}`,
					value: room.id
				}
			})
		},
	},
	onLoad(opts){
		// 获取所有房号
		uni.request({
			header:{
				Authorization: 'Bearer ' + app.globalData.token,
			},
			method:'GET',
			fail: (err) => {
				console.error(err)
			},
			url:'https://api.isaim.cn/citizenry/citizen/roomList',	
			success: (res) => {
				const {data} = res
				console.log(data)
				if(data.code==200){
					this.get.rooms = data.data
				}else if(data.code==500){
					uni.showToast({
						icon:'none',
						title:res.errMsg
					})
				}
			}
		})
	},
}